﻿Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D

Public Class OptionsDialog

    Private Sub OptionsDialog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Icon = My.Resources.ProgramIcon
        txtPath.Text = opts.ExportPath
        chkRotate.Checked = opts.RotateImages

        Select Case opts.Quality
            Case InterpolationMode.HighQualityBicubic : cboQuality.SelectedIndex = 0
            Case InterpolationMode.High : cboQuality.SelectedIndex = 1
            Case InterpolationMode.Default : cboQuality.SelectedIndex = 2
            Case InterpolationMode.Low : cboQuality.SelectedIndex = 3
            Case Else : cboQuality.SelectedIndex = 0
        End Select

        Select Case opts.Sizing
            Case 0 : cboSizing.SelectedIndex = 0
            Case 1 : cboSizing.SelectedIndex = 1
            Case Else : cboSizing.SelectedIndex = 0
        End Select

        chkCopyTo.Checked = opts.CopyToPlayer
        For Each drive_info As DriveInfo In DriveInfo.GetDrives()
            cboDrive.Items.Add(drive_info.Name)
        Next drive_info
        cboDrive.SelectedIndex = 0
        cboDrive.SelectedItem = TryCast(opts.PlayerPath, Object)

        If chkCopyTo.Checked Then
            cboDrive.Enabled = True
        Else
            cboDrive.Enabled = False
        End If
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        Select Case cboQuality.SelectedIndex
            Case 0 : opts.Quality = InterpolationMode.HighQualityBicubic
            Case 1 : opts.Quality = InterpolationMode.High
            Case 2 : opts.Quality = InterpolationMode.Default
            Case 3 : opts.Quality = InterpolationMode.Low
        End Select

        Select Case cboSizing.SelectedIndex
            Case 0 : opts.Sizing = 0
            Case 1 : opts.Sizing = 1
        End Select

        opts.PlayerPath = TryCast(cboDrive.SelectedItem, String)
        opts.RotateImages = chkRotate.Checked
        opts.CopyToPlayer = chkCopyTo.Checked
        opts.ExportPath = txtPath.Text
        SaveAppSettings()
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub chkCopyTo_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCopyTo.CheckedChanged
        cboDrive.Enabled = chkCopyTo.Checked
        txtPath.Enabled = Not chkCopyTo.Checked
    End Sub

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        Dim dlgBrowse As New FolderBrowserDialog
        dlgBrowse.SelectedPath = txtPath.Text
        If dlgBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
            txtPath.Text = dlgBrowse.SelectedPath
        End If
    End Sub

End Class
